package it.unibo.refolding.pico.mfp;

public interface Dwell {

  DwellSetting type();

  double totalTimeS();

  double towardsDelayS();

  double awayDelayS();

  public static class DwellTowards implements Dwell {

    private final double dwellTime;
    final double dwellRate;

    public DwellTowards(double dwellTime, double dwellRate) {
      this.dwellTime = dwellTime;
      this.dwellRate = dwellRate;
    }

    @Override
    public DwellSetting type() {
      return DwellSetting.TOWARDS;
    }

    @Override
    public double totalTimeS() {
      return towardsDelayS();
    }

    @Override
    public double towardsDelayS() {
      return dwellTime;
    }

    @Override
    public double awayDelayS() {
      return 0;
    }
  }

  public static class DwellAway implements Dwell {

    private final double dwellTime;
    final double dwellRate;

    public DwellAway(double dwellTime, double dwellRate) {
      this.dwellTime = dwellTime;
      this.dwellRate = dwellRate;
    }

    @Override
    public DwellSetting type() {
      return DwellSetting.AWAY;
    }

    @Override
    public double totalTimeS() {
      return towardsDelayS() + awayDelayS();
    }

    @Override
    public double towardsDelayS() {
      return 0;
    }

    @Override
    public double awayDelayS() {
      return dwellTime;
    }
  }

  public static class DwellNone implements Dwell {

    public static final DwellNone INSTANCE = new DwellNone();

    @Override
    public DwellSetting type() {
      return DwellSetting.NONE;
    }

    @Override
    public double totalTimeS() {
      return towardsDelayS() + awayDelayS();
    }

    @Override
    public double towardsDelayS() {
      return 0;
    }

    @Override
    public double awayDelayS() {
      return 0;
    }
  }

  public static class DwellBoth implements Dwell {

    private final double dwellTime;
    final double dwellRate;

    public DwellBoth(double dwellTime, double dwellRate) {
      this.dwellTime = dwellTime;
      this.dwellRate = dwellRate;
    }

    @Override
    public DwellSetting type() {
      return DwellSetting.BOTH;
    }

    @Override
    public double totalTimeS() {
      return towardsDelayS() + awayDelayS();
    }

    @Override
    public double towardsDelayS() {
      return dwellTime;
    }

    @Override
    public double awayDelayS() {
      return dwellTime;
    }
  }
}
